package org.amse.ys.sndeditor.model.filesearcher;

import java.io.File;

import org.amse.ys.sndeditor.model.ISoundFileDescription;

public class SoundFileDescription implements ISoundFileDescription {
	private int mySize;
	private File myFile;

	public File giveFile() {
		return myFile;
	}

	public int giveSize() {
		return mySize;
	}

	public void setSize(int size) {
		mySize = size;

	}

	public String extractFileName() {
		return myFile.getName();
	}

	public int compareTo(ISoundFileDescription another) {
		String s1 = this.extractAbsoluteFileName();

		int len1 = s1.length();
		String s2 = another.extractAbsoluteFileName();

		int len2 = s2.length();
		int maxI = Math.min(len1, len2);
		for (int i = 0; i < maxI; i++) {
			if (s1.charAt(i) > s2.charAt(i)) {
				return 1;
			} else if (s1.charAt(i) < s2.charAt(i)) {
				return -1;
			}
		}
		if (len1 == len2) {
			return 0;
		} else if (len1 > len2) {
			return 1;
		}
		return -1;
	}

	@Override
	public int hashCode() {
		return myFile.getName().hashCode();
	}

	@Override
	public boolean equals(Object o) {
		if (o instanceof SoundFileDescription) {
			return myFile.getName().equals(
					((SoundFileDescription) o).giveFile().getName());
		}
		return false;
	}

	@Override
	public void setFile(File file) {
		myFile = file;
		mySize = (int) file.length();
	}

	@Override
	public String extractAbsoluteFileName() {
		return myFile.getAbsolutePath() + "/" + myFile.getName();
	}

}
